package org.smartboot.flow.core.parser.definition;

import org.smartboot.flow.core.component.ChooseComponent;
import org.smartboot.flow.core.parser.DefinitionVisitor;
import org.smartboot.flow.core.util.AssertUtil;

import java.util.List;

/**
 * @author huqiang
 * @since 2022/11/16 15:29
 */
public class ChooseDefinition extends ElementDefinition {

    private ElementDefinition chooseDefaultRef;

    private List<ElementDefinition> chooseCaseList;

    public ElementDefinition getChooseDefaultRef() {
        return this.chooseDefaultRef;
    }

    public void setChooseDefaultRef(ElementDefinition chooseDefaultRef) {
        this.chooseDefaultRef = chooseDefaultRef;
    }

    public List<ElementDefinition> getChooseCaseList() {
        return this.chooseCaseList;
    }

    public void setChooseCaseList(List<ElementDefinition> chooseCaseList) {
        this.chooseCaseList = chooseCaseList;
    }

    @Override
    public void validate() {
        AssertUtil.notNull(chooseCaseList, "choose branch is empty");
        AssertUtil.isTrue(chooseCaseList.size() > 0, "choose branch is empty");
        chooseCaseList.forEach(ElementDefinition::validate);

        if (chooseDefaultRef != null) {
            chooseDefaultRef.validate();
        }
    }

    @Override
    public void visit0(DefinitionVisitor visitor) {
        visitor.visit(this);
    }

    @Override
    public Class<?> resolveType() {
        return ChooseComponent.class;
    }
}
